import { getTradeInfo, userAddress } from "@/api"

/*
 * @Author: your name
 * @Date: 2021-03-25 09:41:48
 * @LastEditTime: 2021-03-25 10:50:37
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \vue-glshaop-client\src\store\trade.js
 */
const state = {
  tradeInfo: {},
  userAddress: []
}
const mutations = {
  RESOVE_TRADEINFO (state, tradeInfo) {
    state.tradeInfo = tradeInfo
  },
  RESOVE_USERADDRESS (state, userAddress) {
    state.userAddress = userAddress
  }
}
const actions = {
  //获取订单信息
  async getTradeInfo ({ commit }) {
    const result = await getTradeInfo()
    if (result.code === 200) {
      commit('RESOVE_TRADEINFO', result.data)
    }
  },
  //获取用户地址
  async getUserAddress ({ commit }) {
    const result = await userAddress()
    if (result.code === 200) {
      commit('RESOVE_USERADDRESS', result.data)
    }
  }
}
const getters = {
  detailArrayList (state) {
    return state.tradeInfo.detailArrayList || {}
  }
}
export default {
  state,
  mutations,
  actions,
  getters
}